package com.ruoyi.yljf.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.yljf.mapper.LecturerMapper;
import com.ruoyi.yljf.domain.Lecturer;
import com.ruoyi.yljf.service.ILecturerService;

import javax.annotation.Resource;

/**
 * 讲师Service业务层处理
 * 
 * @author metaee
 * @date 2025-03-05
 */
@Service
public class LecturerServiceImpl extends ServiceImpl<LecturerMapper, Lecturer> implements ILecturerService {
    @Resource
    private LecturerMapper lecturerMapper;
    
    /**
     * 查询讲师列表
     * 
     * @param lecturer 讲师
     * @return 讲师
     */
    @Override
    public List<Lecturer> selectLecturerList(Lecturer lecturer) {
    	LambdaQueryWrapper<Lecturer> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotEmpty(lecturer.getLecturerName())) {
			queryWrapper.like(Lecturer::getLecturerName, lecturer.getLecturerName());
		}
        return lecturerMapper.selectList(queryWrapper);
    }

    @Override
    public Map<Long, String> getNamesByIds(Set<Long> lecturerIds) {
        if (lecturerIds == null || lecturerIds.isEmpty())  {
            return Collections.emptyMap();
        }
        // 去重 ID 列表
        Set<Long> uniqueIds = new HashSet<>(lecturerIds);
        // 查询数据库
//        List<Lecturer> lecturers = lecturerMapper.selectLecturersByIds(uniqueIds);
        List<Lecturer> lecturers = lecturerMapper.selectBatchIds(uniqueIds);
        ;
        // 转换为 Map
        return lecturers.stream()
                .collect(Collectors.toMap(Lecturer::getId,  Lecturer::getLecturerName));
    }
}
